home *** CD-ROM | disk | FTP | other *** search
Wrap
Public Class TextColorFontForm Inherits System.Windows.Forms.Form #Region " Windows Form Designer generated code " Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() 'Add any initialization after the InitializeComponent() call End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean) If disposing Then If Not (components Is Nothing) Then components.Dispose() End If End If MyBase.Dispose(disposing) End Sub Friend WithEvents TextBox1 As System.Windows.Forms.TextBox Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox Friend WithEvents cboKnownColors As System.Windows.Forms.ComboBox Friend WithEvents lblRed As System.Windows.Forms.Label Friend WithEvents lblGreen As System.Windows.Forms.Label Friend WithEvents lblBlue As System.Windows.Forms.Label Friend WithEvents tbarRed As System.Windows.Forms.TrackBar Friend WithEvents tbarBlue As System.Windows.Forms.TrackBar Friend WithEvents tbarGreen As System.Windows.Forms.TrackBar Friend WithEvents lblColor As System.Windows.Forms.Label Friend WithEvents FontDialog1 As System.Windows.Forms.FontDialog Friend WithEvents btnFont As System.Windows.Forms.Button 'Required by the Windows Form Designer Private components As System.ComponentModel.Container 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Me.GroupBox1 = New System.Windows.Forms.GroupBox() Me.tbarRed = New System.Windows.Forms.TrackBar() Me.tbarBlue = New System.Windows.Forms.TrackBar() Me.tbarGreen = New System.Windows.Forms.TrackBar() Me.lblBlue = New System.Windows.Forms.Label() Me.lblGreen = New System.Windows.Forms.Label() Me.lblRed = New System.Windows.Forms.Label() Me.GroupBox2 = New System.Windows.Forms.GroupBox() Me.cboKnownColors = New System.Windows.Forms.ComboBox() Me.btnFont = New System.Windows.Forms.Button() Me.lblColor = New System.Windows.Forms.Label() Me.TextBox1 = New System.Windows.Forms.TextBox() Me.FontDialog1 = New System.Windows.Forms.FontDialog() Me.GroupBox1.SuspendLayout() CType(Me.tbarRed, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.tbarBlue, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.tbarGreen, System.ComponentModel.ISupportInitialize).BeginInit() Me.GroupBox2.SuspendLayout() Me.SuspendLayout() ' 'GroupBox1 ' Me.GroupBox1.Controls.AddRange(New System.Windows.Forms.Control() {Me.tbarRed, Me.tbarBlue, Me.tbarGreen, Me.lblBlue, Me.lblGreen, Me.lblRed}) Me.GroupBox1.Location = New System.Drawing.Point(24, 152) Me.GroupBox1.Name = "GroupBox1" Me.GroupBox1.Size = New System.Drawing.Size(264, 152) Me.GroupBox1.TabIndex = 2 Me.GroupBox1.TabStop = False Me.GroupBox1.Text = "FromARGB method" ' 'tbarRed ' Me.tbarRed.Location = New System.Drawing.Point(80, 24) Me.tbarRed.Maximum = 255 Me.tbarRed.Name = "tbarRed" Me.tbarRed.Size = New System.Drawing.Size(176, 42) Me.tbarRed.TabIndex = 1 Me.tbarRed.TickFrequency = 16 Me.tbarRed.Value = 255 ' 'tbarBlue ' Me.tbarBlue.Location = New System.Drawing.Point(80, 107) Me.tbarBlue.Maximum = 255 Me.tbarBlue.Name = "tbarBlue" Me.tbarBlue.Size = New System.Drawing.Size(176, 42) Me.tbarBlue.TabIndex = 1 Me.tbarBlue.TickFrequency = 16 Me.tbarBlue.Value = 255 ' 'tbarGreen ' Me.tbarGreen.Location = New System.Drawing.Point(80, 66) Me.tbarGreen.Maximum = 255 Me.tbarGreen.Name = "tbarGreen" Me.tbarGreen.Size = New System.Drawing.Size(176, 42) Me.tbarGreen.TabIndex = 1 Me.tbarGreen.TickFrequency = 16 Me.tbarGreen.Value = 255 ' 'lblBlue ' Me.lblBlue.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblBlue.ForeColor = System.Drawing.Color.Blue Me.lblBlue.Location = New System.Drawing.Point(8, 112) Me.lblBlue.Name = "lblBlue" Me.lblBlue.Size = New System.Drawing.Size(56, 16) Me.lblBlue.TabIndex = 0 Me.lblBlue.Text = "Blue" Me.lblBlue.TextAlign = System.Drawing.ContentAlignment.MiddleRight ' 'lblGreen ' Me.lblGreen.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblGreen.ForeColor = System.Drawing.Color.Green Me.lblGreen.Location = New System.Drawing.Point(8, 64) Me.lblGreen.Name = "lblGreen" Me.lblGreen.Size = New System.Drawing.Size(56, 16) Me.lblGreen.TabIndex = 0 Me.lblGreen.Text = "Green" Me.lblGreen.TextAlign = System.Drawing.ContentAlignment.MiddleRight ' 'lblRed ' Me.lblRed.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblRed.ForeColor = System.Drawing.Color.Red Me.lblRed.Location = New System.Drawing.Point(8, 24) Me.lblRed.Name = "lblRed" Me.lblRed.Size = New System.Drawing.Size(56, 16) Me.lblRed.TabIndex = 0 Me.lblRed.Text = "Red" Me.lblRed.TextAlign = System.Drawing.ContentAlignment.MiddleRight ' 'GroupBox2 ' Me.GroupBox2.Controls.AddRange(New System.Windows.Forms.Control() {Me.cboKnownColors}) Me.GroupBox2.Location = New System.Drawing.Point(24, 72) Me.GroupBox2.Name = "GroupBox2" Me.GroupBox2.Size = New System.Drawing.Size(264, 72) Me.GroupBox2.TabIndex = 4 Me.GroupBox2.TabStop = False Me.GroupBox2.Text = "FromName method" ' 'cboKnownColors ' Me.cboKnownColors.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList Me.cboKnownColors.DropDownWidth = 208 Me.cboKnownColors.Location = New System.Drawing.Point(24, 32) Me.cboKnownColors.Name = "cboKnownColors" Me.cboKnownColors.Size = New System.Drawing.Size(224, 26) Me.cboKnownColors.TabIndex = 3 ' 'btnFont ' Me.btnFont.Location = New System.Drawing.Point(304, 24) Me.btnFont.Name = "btnFont" Me.btnFont.Size = New System.Drawing.Size(112, 40) Me.btnFont.TabIndex = 7 Me.btnFont.Text = "Select Font" ' 'lblColor ' Me.lblColor.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D Me.lblColor.Location = New System.Drawing.Point(24, 312) Me.lblColor.Name = "lblColor" Me.lblColor.Size = New System.Drawing.Size(264, 24) Me.lblColor.TabIndex = 6 ' 'TextBox1 ' Me.TextBox1.Location = New System.Drawing.Point(24, 32) Me.TextBox1.Name = "TextBox1" Me.TextBox1.Size = New System.Drawing.Size(256, 24) Me.TextBox1.TabIndex = 0 Me.TextBox1.Text = "Sample Text" ' 'TextColorFontForm ' Me.AutoScaleBaseSize = New System.Drawing.Size(7, 17) Me.ClientSize = New System.Drawing.Size(440, 349) Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.btnFont, Me.lblColor, Me.TextBox1, Me.GroupBox1, Me.GroupBox2}) Me.Font = New System.Drawing.Font("Microsoft Sans Serif", 11!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Name = "TextColorFontForm" Me.Text = "TextColorFontForm" Me.GroupBox1.ResumeLayout(False) CType(Me.tbarRed, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.tbarBlue, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.tbarGreen, System.ComponentModel.ISupportInitialize).EndInit() Me.GroupBox2.ResumeLayout(False) Me.ResumeLayout(False) End Sub #End Region Private Sub TextColorFontForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' first combo item is special cboKnownColors.Items.Add("<not a known color>") ' fill the combobox with the list of known colors Dim colorName As String For Each colorName In [Enum].GetNames(GetType(KnownColor)) cboKnownColors.Items.Add(colorName) Next ' select the first item cboKnownColors.SelectedIndex = 0 End Sub ' this event fires when a color scrollbar is moved Private Sub ColorBar_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbarRed.Scroll, tbarGreen.Scroll, tbarBlue.Scroll UpdateControlValues(Color.FromArgb(tbarRed.Value, tbarGreen.Value, tbarBlue.Value)) End Sub ' the user has selected a different Known color Private Sub cboKnownColors_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboKnownColors.SelectedIndexChanged If Not cboKnownColors.Text.StartsWith("<") AndAlso cboKnownColors.Text <> "Transparent" Then UpdateControlValues(Color.FromName(cboKnownColors.Text)) End If End Sub ' update control values Sub UpdateControlValues(ByVal c As Color) TextBox1.BackColor = c ' split the color in its three components tbarRed.Value = c.R tbarGreen.Value = c.G tbarBlue.Value = c.B ' display color components in bottom label lblColor.Text = String.Format("Red={0}, Green={1}, Blue={2}", c.R, c.G, c.B) ' try to assign a known color cboKnownColors.Text = c.ToKnownColor.ToString ' if it failed, display first element If cboKnownColors.Text <> c.ToKnownColor.ToString Then cboKnownColors.SelectedIndex = 0 End If End Sub ' display the Font dialog Private Sub btnFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFont.Click With FontDialog1 .Font = TextBox1.Font If .ShowDialog() = DialogResult.OK Then TextBox1.Font = .Font End If End With End Sub Private Sub TextBox1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyDown e.Handled = True End Sub End Class